import { useRef } from "react"
import type { RefObject } from "react"

export type RefsList<T> = T[] & {
  set: (el: T | null) => void
}

export function useRefsList<T = HTMLElement>() {
  const refs = useRef<T[]>([]) as RefObject<RefsList<T>>
  refs.current.set = (el: T | null) => {
    el ? refs.current.push(el) : refs.current.pop()
  }
  return refs
}
